<?php

namespace app\admin\controller\channel;

use app\admin\controller\AdminController;
use app\admin\service\channel\AppletService;
use think\response\Json;

class Applet extends AdminController
{
    /**
     * 获取小程序渠道配置
     * @return Json
     */
    public function getAppletConfig()
    {
        $result = AppletService::getAppletConfig();
        return $this->data($result);
    }

    /**
     * 设置小程序渠道配置
     * @return Json
     */
    public function setAppletConfig()
    {
        $params = $this->postData([
            ['name', ''],
            ['original_id', ''],
            ['qr_code', ''],
            ['app_id', ''],
            ['app_secret', ''],
            ['token', ''],
            ['encoding_aes_key', ''],
            ['encryption_type', '']
        ]);

        $result = AppletService::setAppletConfig($params);
        if(true === $result) {
            return $this->success([], '设置成功');
        } else {
            return $this->error(AppletService::getError());
        }
    }
}